//
//  VehicleDetailsViewController.swift
//  koolcar
//
//  Created by kuaimaxiansheng on 2023/10/12.
//

import UIKit

class VehicleDetailsViewController: BaseViewController {
    
    var collectBtn: UIButton! //收藏
    var id = ""
    var bottomView: BottomPriceView!
    var bgBavView: UIView!
    var tableView: BaseTableView!
    var contentModel: CarDetailsContentModel!
    var recommendArray: [VehicleLisetModel] = []
    var videoVrPdfArray = NSMutableArray()
    var seaCarFlag: Bool = false //海外车
    var priceTipLab: UILabel! //海外车价格说明
    var goTopBtn: UIButton = {
        let tempBtn = UIButton()
        tempBtn.setup_image(image: UIImage.init(named: "icon_suspend"))
        tempBtn.isHidden = true
        return tempBtn
    }()
    
    var whatsAppBtn: UIButton = {
        let tempBtn = UIButton()
        tempBtn.setup_image(image: UIImage.init(named: "whats_app"))
        tempBtn.isHidden = false
        return tempBtn
    }()
    
    var loadingFlag: Bool = false
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navBar.barBackgroundColor = .clear
        self.navBar.isHidden = true
        self.bottomView = BottomPriceView()
        self.bottomView.seaCarFlag = self.seaCarFlag
        self.bottomView.callBack = {[weak self] tag in
            if tag == 0 {
                if self?.seaCarFlag ?? false == false {
                    self?.seeBtnAntion()
                }else{
                    //whatsApp
                    self?.dealWhatsapp()
                }
            }else if tag == 1 {
                //订购
                self?.orderBtnAntion()
            }
        }
        self.view.addSubview(self.bottomView)
        
        self.initTableView()
        self.addInitNav()
        self.view.bringSubview(toFront: self.bottomView)
        goTopBtn.addTarget(self, action: #selector(goTopBtnAction), for: .touchUpInside)
        
        if self.seaCarFlag {
            //海外车辆详情页，右下角的电话图标不需要展示
            whatsAppBtn.isHidden = true
        }
        whatsAppBtn.addTarget(self, action: #selector(whatsAppBtnAction), for: .touchUpInside)
        self.view.addSubview(self.goTopBtn)
        self.view.addSubview(self.whatsAppBtn)
        self.addSnpLayout()
        
        if self.seaCarFlag {
            self.fetchGetSeaCarDetail()
        }else{
            self.requestCarDetailsData()
        }
        
        //延迟停留3秒记录
        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
            self.requestBrowsingHistory()
        }
    }
    
    ///滑到顶部
    @objc func goTopBtnAction(){
        self.tableView.scrollToTop(animated: true)
    }
    
    ///whatsApp跳转
    @objc func whatsAppBtnAction(){
        self.dealWhatsapp()
    }
    
    private func addSnpLayout(){
        self.bottomView.snp.makeConstraints { make in
            make.left.right.equalTo(0)
            make.height.lessThanOrEqualTo(TabbarHeight + 50)
            make.bottom.equalTo(IphoneXMarginBottom > 1 ? -IphoneXMarginBottom : -4)
        }
        
        tableView.snp.makeConstraints { make in
            make.left.right.equalTo(0)
            make.top.equalTo(NavBarHight)
            make.bottom.equalTo(bottomView.snp.top)
        }
        
        self.bottomView.layoutIfNeeded()
        self.goTopBtn.snp.makeConstraints { make in
            make.left.equalTo(12)
            make.width.equalTo(34)
            make.height.equalTo(34)
            make.bottom.equalTo(bottomView.snp.top).offset(-60)
        }
        
        self.whatsAppBtn.snp.makeConstraints { make in
            make.right.equalTo(-12)
            make.width.equalTo(34)
            make.height.equalTo(34)
            make.bottom.equalTo(bottomView.snp.top).offset(-60)
        }
    }
    
    //导航栏
    func addInitNav() {
        
        self.bgBavView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: kScreenWidth, height: NavBarHight))
        self.bgBavView.backgroundColor = UIColor.init(hex: 0xFFFFFF, alpha: 0)
        self.view.addSubview( self.bgBavView)
        
        
        let backBtn = UIButton.init(frame: CGRect.init(x: 14, y: NavBarHight - 34, width: 24, height: 24))
        backBtn.backgroundColor = UIColor(hex: 0x000000 ,alpha: 0.6)
        backBtn.layer.cornerRadius = 12
        backBtn.clipsToBounds = true
        backBtn.setImage(UIImage.init(named: "icon_vehicle_nav_back"), for: .normal)
        backBtn.setImage(UIImage.init(named: "icon_vehicle_nav_back"), for: .highlighted)
        backBtn.addTarget(self, action: #selector(backBtnAction), for: .touchUpInside)
        self.bgBavView.addSubview(backBtn)
        
        
        //kScreenWidth - 104
        let shareBtn = UIButton(frame: CGRect(x: kScreenWidth - 38, y: NavBarHight - 34, width: 24, height: 24))
        shareBtn.backgroundColor = UIColor(hex: 0x000000 ,alpha: 0.6)
        shareBtn.layer.cornerRadius = 12
        shareBtn.clipsToBounds = true
        shareBtn.setImage(UIImage(named: "icon_normal_white_share"), for: .normal)
        shareBtn.setImage(UIImage(named: "icon_normal_white_share"), for: .selected)
        shareBtn.addTarget(self, action: #selector(shareBtnAntion(sender:)), for: .touchUpInside)
        shareBtn.isHidden = false
        self.bgBavView.addSubview(shareBtn)
        
        //kScreenWidth - 74
        self.collectBtn = UIButton(frame: CGRect(x: kScreenWidth - 76, y: NavBarHight - 34, width: 24, height: 24))
        collectBtn.backgroundColor = UIColor(hex: 0x000000 ,alpha: 0.6)
        collectBtn.layer.cornerRadius = 12
        collectBtn.clipsToBounds = true
        self.collectBtn.setImage(UIImage(named: "icon_vehicle_normal_c"), for: .normal)
        self.collectBtn.setImage(UIImage(named: "icon_vehicle_select_c"), for: .selected)
        self.collectBtn.addTarget(self, action: #selector(collectBtnAntion), for: .touchUpInside)
        self.bgBavView.addSubview(self.collectBtn)
    }
    
    
    func initTableView(){
        self.tableView = BaseTableView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight - TabbarHeight - 50), style: .grouped)
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.backgroundColor = .white
        self.tableView.rowHeight = UITableViewAutomaticDimension
        self.tableView.estimatedRowHeight = 2
        self.tableView.register(VehicleDeatailsTopCell.self, forCellReuseIdentifier: "VehicleDeatailsTopCell")
        self.tableView.register(CalculatorTableViewCell.self, forCellReuseIdentifier: "CalculatorTableViewCell")//购车计算器
        self.tableView.register(ParameterTableViewCell.self, forCellReuseIdentifier: "ParameterTableViewCell")//基础参数
        self.tableView.register(SpecificationTableViewCell.self, forCellReuseIdentifier: "SpecificationTableViewCell")//汽车规格
        self.tableView.register(AssuranceableViewCell.self, forCellReuseIdentifier: "AssuranceableViewCell")//更多资料
        self.tableView.register(RecommendedTableViewCell.self, forCellReuseIdentifier: "RecommendedTableViewCell")//推荐车辆
        self.view.addSubview(self.tableView)
        
    }
    
    //MARK - Request
    //保存浏览记录
    func requestBrowsingHistory(){
        var param = NSMutableDictionary() as! [String : String]
        param["browsingId"] = self.id
        XTRequestCenter.shared.sendRequestMappableTargetObject(target: APIManager.browsingHistory(param: param), objectType: CommondResModel.self, finished: { (response) in
            let resultObj = response as! CommondResModel
            if (resultObj.code == "1") {
            }
        }) { (error ) in
            print(error as Any)
        }
    }
    
    ///获取海外车
    private func fetchGetSeaCarDetail(){
        self.view.showLoadingHUDText(nil)
        XTRequestCenter.shared.sendRequestMappableTargetObject(target: APIManager.goonetcarDetail(param: ["id": self.id]), objectType: CarDetailsModel.self) { data in
            self.view.handleLoading()
            let resultObj = data as! CarDetailsModel
            if resultObj.code == "1" {
                self.contentModel = resultObj.data
                
                let paramStr = self.contentModel?.otherParameter ?? ""
                if paramStr != ""{
                    self.contentModel?.otherParameterModel = [OtherinfoModel].init(JSONString: paramStr, context: nil)
                }
                
                self.dealVideoVrPdf(model: self.contentModel)
                
                //contentModel
                
                //推荐收藏
                self.recommendArray = self.contentModel?.carRelationList ?? []
                self.recommendArray.forEach { itmes in
                    itmes.favoriteBlock = { [weak self] in
                        self?.requestFavorite(model: itmes, isList: true)
                    }
                }
                self.bottomTitle(model: self.contentModel)
                //是否收藏
                if self.contentModel?.favorite == true{
                    self.collectBtn.isSelected = true
                }else{
                    self.collectBtn.isSelected = false
                }
            }else{
                self.view.makeToastBottom(message: resultObj.msg ?? "")
            }
            self.loadingFlag = true
            self.tableView.reloadData()
        } error: { err in
            self.loadingFlag = true
            self.view.handleLoading()
            self.view.makeToastBottom(message: err?.domain ?? "")
        }
    }
    
    //车辆详情
    private func requestCarDetailsData() {
        self.view.showLoadingHUDText(nil)
        XTRequestCenter.shared.sendRequestMappableTargetObject(target: APIManager.carDetailsData(param: ["id": self.id]), objectType: CarDetailsModel.self) { data in
            self.view.handleLoading()
            let resultObj = data as! CarDetailsModel
            if resultObj.code == "1" {
                self.contentModel = resultObj.data
                
                let paramStr = self.contentModel?.otherParameter ?? ""
                if paramStr != ""{
                    self.contentModel?.otherParameterModel = [OtherinfoModel].init(JSONString: paramStr, context: nil)
                }
                
                self.dealVideoVrPdf(model: self.contentModel)
                
                //推荐收藏
                self.recommendArray = self.contentModel?.carRelationList ?? []
                self.recommendArray.forEach { itmes in
                    itmes.favoriteBlock = { [weak self] in
                        self?.requestFavorite(model: itmes, isList: true)
                    }
                }
                self.bottomTitle(model: self.contentModel)
                //是否收藏
                if self.contentModel?.favorite == true{
                    self.collectBtn.isSelected = true
                }else{
                    self.collectBtn.isSelected = false
                }
            }else{
                self.view.makeToastBottom(message: resultObj.msg ?? "")
            }
            self.loadingFlag = true
            self.tableView.reloadData()
        } error: { err in
            self.loadingFlag = true
            self.view.handleLoading()
            self.view.makeToastBottom(message: err?.domain ?? "")
        }
    }
    
    func bottomTitle(model: CarDetailsContentModel? = nil){
        self.bottomView.showSpecial = model?.isSpecial ?? false
        self.bottomView.showPriceTipFlag = self.seaCarFlag
        self.bottomView.totalPrice = model?.price ?? 0
        if self.seaCarFlag {
            self.bottomView.originPrice = 0
        }else{
            self.bottomView.originPrice = model?.originalPrice ?? 0
        }
        if model?.isSell ?? false {
            //已售出
            self.bottomView.carStatus = 1
        }else{
            //未售出
            if model?.isReserve ?? false {
                //已预订
                self.bottomView.carStatus = 2
            }else{
                //未预订
                self.bottomView.carStatus = 0
                self.bottomView.orderPrice = self.seaCarFlag ? (model?.subscription ?? 0) : (model?.orderPrice ?? 0)
            }
        }
    }
    
    
    //处理视频、vr、pdf
    func dealVideoVrPdf(model: CarDetailsContentModel){
        //视频
        if model.videoUrl ?? "" != ""{
            let dataModel = VideoVRPdfModel.init()
            dataModel.name = MMLocalizedString("vehicle_video", comment: "车辆视频")
            dataModel.content = model.videoUrl ?? ""
            dataModel.image = "icon_vehicle_video"
            dataModel.type = 0
            self.videoVrPdfArray.add(dataModel)
        }
        
        //vr页面中的图片数组： stereoscopicAppearanceImages
        //vr的图片：interiorImages
        if (model.interiorImages ?? "") != "" ||
            (model.stereoscopicAppearanceImages ?? "") != "" {
            let dataModel = VideoVRPdfModel.init()
            dataModel.name = MMLocalizedString("vr", comment: "车厢VR")
            dataModel.content = model.interiorImages ?? ""
            dataModel.image = "icon_vr"
            dataModel.type = 1
            self.videoVrPdfArray.add(dataModel)
        }
        
        if model.reportPdf ?? "" != ""{
            let dataModel = VideoVRPdfModel.init()
            dataModel.name = MMLocalizedString("OBD", comment: "OBD报告")
            dataModel.content = model.reportPdf ?? ""
            dataModel.image = "icon_OBD"
            dataModel.type = 2
            self.videoVrPdfArray.add(dataModel)
        }
        
        model.videoVrPdfList = (self.videoVrPdfArray as! [VideoVRPdfModel])
    }
    
    ///收藏取消收藏
    func requestFavorite(model: VehicleLisetModel, isList: Bool){
        if UserModule.shared.isLogined == false{
            self.jumpToLogin()
            return
        }
        var param = NSMutableDictionary() as! [String: String]
        param["usedcarId"] = "\(model.id ?? 0)"
        if self.seaCarFlag {
            param["dataType"] = "2"
        }
        XTRequestCenter.shared.sendRequestMappableTargetObject(target: APIManager.favorite(param: param),objectType: CommondResModel.self) { data in
            let resultObj = data as! CommondResModel
            if resultObj.code == "1" {
                if model.favorite == false {
                    self.view.makeToast(message: MMLocalizedString("successful_collection", comment: "收藏成功"))
                    self.collectBtn.isSelected = true
                    if isList {
                        model.favorite = true
                    }else{
                        self.contentModel?.favorite = true
                    }
                }else{
                    self.view.makeToast(message: MMLocalizedString("uncollected", comment: "已取消收藏"))
                    self.collectBtn.isSelected = false
                    if isList {
                        model.favorite = false
                    }else{
                        self.contentModel?.favorite = false
                    }
                }
                self.tableView.reloadData()
            }else{
                self.view.makeToast(message: resultObj.msg ?? "")
            }
        }error: { err in
            self.view.makeToast(message: err?.domain ?? "")
        }
    }
    
    //MARK: - Antion
    func jumpToLogin(){
        guard let tabbarVC = UIApplication.shared.keyWindow?.rootViewController as? BaseTabbarController else {
            return
        }
        XTManageCenter.shared.jumpToLoginView()
//        let vc = LoginViewController()
//        let loginNavi = BaseNavigationController.init(rootViewController: vc)
//        loginNavi.modalPresentationStyle = .fullScreen
//        tabbarVC.present(loginNavi, animated: true)
    }
    
    
    @objc func backBtnAction() {
        self.navigationController?.popViewController(animated: true)
    }
    
    
    //收藏
    @objc func collectBtnAntion() {
        let model = VehicleLisetModel.init()
        model.id = self.contentModel?.id
        model.favorite = self.contentModel?.favorite
        self.requestFavorite(model: model, isList: false)
    }
    
    
    //分享
    @objc func shareBtnAntion(sender: UIButton) {
        let VC = ShareViewController()
        VC.titleStr = MMLocalizedString("share", comment: "分享")
        VC.isfaceBook = true
        //MMLocalizedString("share_article", comment: "我想与您分享以下文章") +
        VC.shareContent = self.contentModel?.shareText ?? ""
        VC.shareUrl = self.contentModel?.shareText ?? ""
        VC.modalPresentationStyle = .overFullScreen
        self.present(VC, animated: false, completion: nil)
    }
    
    @objc func seeBtnAntion(){
        self.dealWhatsapp()
    }
    
    func dealWhatsapp(){
        
        var tempStr = self.contentModel?.shareText ?? ""
        let phone = "85262501888"
        tempStr = tempStr.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
        
        var tempUrl = "whatsapp://send?text=\(tempStr)"
        if (phone != "") {
            tempUrl = "whatsapp://send?phone=\(phone)&text=\(tempStr)"
        }
        guard let url = URL.init(string: tempUrl) else {
            return
        }
        
        if UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }else{//没安装WhatsApp
            var str = self.contentModel?.shareText ?? ""
            str = str.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!//反编码，如果没有不成功
            let noTemUrl = "https://wa.me/85262501888?text=Hi!" + str
            
            guard let url = URL.init(string: noTemUrl) else {
                return
            }
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
    }
    
    
    //订购
    @objc func orderBtnAntion(){
        if UserModule.shared.isLogined == false{
            self.jumpToLogin()
            return
        }
        if self.contentModel == nil{
            return
        }
        
        let vc = VehicleInfoViewController()
        vc.contentModel = self.contentModel
        vc.seaCarFlag = self.seaCarFlag
        vc.carOrderSucceedBlock = { [weak self] in
            //订购成功后刷新一次
            self?.requestCarDetailsData()
            
        }
        self.navigationController?.pushViewController(vc, animated: true)
        
        
        //        if UserModule.shared.isLogined == false{
        //            self.jumpToLogin()
        //            return
        //        }
        //        if self.contentModel == nil{
        //            return
        //        }
        //        let vc = ReservedWheelViewController()
        //        vc.model = self.contentModel
        //        self.navigationController?.pushViewController(vc, animated: true)
        //        //订购成功
        //        vc.carOrderSucceedBlock = { [weak self] in
        //            self?.requestCarDetailsData()
        //        }
    }
    
    
    ///获取保障服务
    ///海外车从webOptionalEquipments、additionalOptionalEquipments、optionalEquipments 三个中取"isHas":"1"的"equipmentName"对应的Value展示出来
    private func fetchGetAssuranceHtml() -> String {
        guard self.seaCarFlag else {
            //本地车
            return (self.contentModel?.assurance ?? "") + (self.contentModel?.carFacilityDetail ?? "")
        }
        
        //海外车辆
        //var tempHtml = ""
        let tempArr1 =  self.contentModel?.optionalEquipments ?? []
        let tempArr2 = self.contentModel?.webOptionalEquipments ?? []
        let tempArr3 = self.contentModel?.additionalOptionalEquipments ?? []
        
        let lastArr = tempArr1 + tempArr2 + tempArr3
        let nameArr1 = lastArr.filter{$0.isHas ?? "" == "1"}.map{$0.equipmentName ?? ""}
        
        guard nameArr1.count > 0 else {
            return ""
        }
        
        let htmlContent = nameArr1.map { str in
            return String(format: "<li>%@</li>", str)
        }
        let localHtmlStr = htmlContent.joined()
        let formatWeb = """
                <!DOCTYPEhtml>
                    <html>
                    <head>
                        <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"name="viewport">
                        <meta http-equiv="Content-Type"content="text/html; charset=UTF-8">
                    </head>
                    <style type="text/css">
                        .mycss{padding: 10px;}
                        .mycss li {
                            font-size: 12px;
                            float: left;
                            width: 47%@;
                            padding-right: 3%@;
                        }
                    </style>
                    <body style="background-color: white; border">
                        <div style="width: 100%@;">
                            <ul class="mycss">
                                %@
                            </ul>
                        </div>
                    </body>
                    </html>
                """
        let tempStr = String(format: formatWeb,
                             "%","%","%",
                             localHtmlStr)
        return tempStr
    }
}


extension VehicleDetailsViewController: UITableViewDelegate,UITableViewDataSource{
    func numberOfSections(in tableView: UITableView) -> Int {
        return 6
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        if self.seaCarFlag && indexPath.section == 1 {
            //海外车不显示购车计算器
            return 0.01
        }
        
        //        if (self.contentModel?.otherParameterJsonNew ?? []).count == 0 && indexPath.section == 3 {
        //            return 0.01
        //        }
        
        
        //服务保障
        if indexPath.section == 4 && self.fetchGetAssuranceHtml() == "" {
            return 0.01
            //            if (self.contentModel?.assurance ?? "") == "" {
            //                return 0.01
            //            }
        }
        
        if self.recommendArray.count == 0 && indexPath.section == 5{//推荐车辆
            return 0.01
        }
        
        return UITableViewAutomaticDimension
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        switch indexPath.section {
            case 0:
                let cell = tableView.dequeueReusableCell(withIdentifier: "VehicleDeatailsTopCell", for: indexPath) as! VehicleDeatailsTopCell
                cell.seaCarFlag = self.seaCarFlag
                if self.contentModel != nil{
                    cell.setContentModel(contentModel: self.contentModel)
                }
                return cell
            case 1:
                let cell = tableView.dequeueReusableCell(withIdentifier: "CalculatorTableViewCell", for: indexPath) as! CalculatorTableViewCell
                cell.delegate = self
                return cell
            case 2:
                let cell = tableView.dequeueReusableCell(withIdentifier: "ParameterTableViewCell", for: indexPath) as! ParameterTableViewCell
                cell.seaCarFlag = self.seaCarFlag
                if self.contentModel != nil{
                    cell.setContentModel(contentModel: self.contentModel)
                }
                return cell
            case 3:
                let cell = tableView.dequeueReusableCell(withIdentifier: "SpecificationTableViewCell", for: indexPath) as! SpecificationTableViewCell
                cell.seaCarFlag = self.seaCarFlag
                cell.setContentModel(contentModel: self.contentModel)
                return cell
            case 4:
                let cell = tableView.dequeueReusableCell(withIdentifier: "AssuranceableViewCell", for: indexPath) as! AssuranceableViewCell
                cell.setAssuranceableViewCell(htmlStr: self.fetchGetAssuranceHtml())
                return cell
                
            default:
                let cell = tableView.dequeueReusableCell(withIdentifier: "RecommendedTableViewCell", for: indexPath) as! RecommendedTableViewCell
                cell.seaCarFlag = self.seaCarFlag
                cell.loadingFlag = self.loadingFlag
                cell.setDetailsModel(data: self.recommendArray)
                return cell
                
        }
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        if section == 5 {
            return 72
        }
        return 0.01
    }
    
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let bgView: UIView = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 0.01))
        bgView.backgroundColor = .white
        return bgView
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.01
    }
    
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let bgView: UIView = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 0.01))
        bgView.backgroundColor = .clear
        return bgView
    }
    
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let offset = scrollView.contentOffset.y
        //naviBar透明度
        let pre = 375.0/375 as CGFloat
        let bannerH = (kScreenWidth * pre) - NavBarHight
        if offset <= 0 {
            self.bgBavView.backgroundColor = UIColor.init(hex: 0xffffff, alpha: 0)
            self.goTopBtn.isHidden = true
        }else{
            let tempAlpha = offset/bannerH
            self.bgBavView.backgroundColor = UIColor.init(hex: 0xffffff, alpha: tempAlpha)
            if tempAlpha >= 1 {
                self.goTopBtn.isHidden = false
            }else{
                self.goTopBtn.isHidden = true
            }
        }
        
        //把self.bgBavView拿到上面
        self.view.bringSubview(toFront: self.bgBavView)
    }
}

//购车计算器
extension VehicleDetailsViewController: CalculatorTableViewCellDelegate{
    func selectCarCalculatorAntion() {
        let vc = PurchaseCalcuViewController()
        vc.model = self.contentModel
        self.navigationController?.pushViewController(vc, animated: true)
    }
}
